<?php
/**
 * Created by PhpStorm.
 * User: td
 * Date: 15/1/9
 * Time: 上午12:32
 */

namespace Home\Controller;
use Think\Controller;

class PublisherController extends Controller {

    //发活者登陆首页
    public function index(){
        //loginStatus();
        //获取有无未读消息
        $message_db = D("Message");
        $message_result = $message_db->getIsRead($_SESSION['loginUser']['user_id']);
        if(is_array($message_result)){
            session('is_read',1);
        }else{
            session('is_read',2);
        }
        $this->display();
    }

    //发活页面pC
    public function indexPC(){
        //loginStatus();
        $this->theme('PC')->display('Publisher/index');
    }

    public function publish() {
        if(isset($_SESSION['loginUser'])){
            $this->assign('curNav', 1);
            $this->display();
        }else{
            $this->display('Login/index');
        }
    }
    //PC端发活页面
    public function publishPC() {
        $this->theme('PC')->display('Publisher/publish');
    }

    //发活首页信息获取
    public function publisherIndex(){
        //loginStatus();
        $user_ext_db = D('UserExt');
        $jobs = $_GET['jobs'];
        $duration = $_GET['duration'];
        $keyword = $_GET['keyword'];
        $page = $_GET['page'];
        $rows = 4;
//        dump($jobs);
        if(IS_GET){
            $result = $user_ext_db->getYInfo($jobs,$duration,$keyword,$page,$rows);
            //dump($result);
            if($result){
                $this->success('获取信息成功!',$result);
            }else{
                $this->error('获取信息失败!');
            }

        }else{
            $this->error('错误方法!');
        }
    }

    //发活首页信息获取
    public function publisherIndexPC(){
        //loginStatus();
        $user_ext_db = D('UserExt');
        $jobs = $_GET['jobs'];
        $duration = $_GET['duration'];
        $page = $_GET['page'];
        $row = $_GET['row'];
        $keyword = $_GET['keyword'];
//        dump($jobs);
        if(IS_GET){
            $result = $user_ext_db->getYInfoPC($jobs,$duration,$page,$row,$keyword);
            //dump($result);
            if($result){
                $this->success('获取信息成功!',$result);
                // dump($result);
            }else{
                $this->error('获取信息失败!');
            }

        }else{
            $this->error('错误方法!');
        }
    }


    //发活页面
    public function publishMission(){
        if(isset($_SESSION['loginUser'])){
            if(IS_POST){
                $user_info = $_SESSION['loginUser'];
                //publisher_id
                $data['publisher_id'] = $user_info['user_id'];
                $data['publisher_name'] = $user_info['user_name'];
                //publish_time
                ini_set('date.timezone','Asia/Shanghai');
                $data['publish_time'] = date('Y-m-d H:i:s',time());
                $data['first_publish_time'] = date('Y-m-d H:i:s',time());
                //提交得信息
                if( $data['publisher_id'] && $_POST['mission_name'] && $_POST['jobs'] && $_POST['duration'] && $_POST['salary1'] && $_POST['location1'] && $_POST['valid_time'] && $_POST['isphone_public'] && $_POST['isagent'] ){
                    $data['mission_name'] = $_POST['mission_name'];
                    $data['jobs'] = $_POST['jobs'];
                    $data['duration'] = $_POST['duration'];
                    $data['salary1'] = $_POST['salary1'];
                    $data['salary2'] = $_POST['salary2'];
                    $data['location1'] = $_POST['location1'];
                    $data['location2'] = $_POST['location2'];
                    $data['description'] = $_POST['description'];
                    $data['valid_time'] = $_POST['valid_time'];
                    $data['isphone_public'] = $_POST['isphone_public'];

                    if(2 == $_POST['isagent']){
                        $user_ext_db = D('UserExt');
                        $data['agent'] = $user_ext_db->getAgent($data['publisher_id']);
                    }else{
                        $data['agent'] = '';
                    }

                    //设置状态
                    $data['status'] = 1;
                    //dump($data);
                    //mission表存入信息
                    //dump($data);
                    $mission_db = M('Mission');
                    $mission_result = $mission_db->add($data);

                    if($mission_result){
                        $this->success("发布成功!",$mission_result);
                    }else{
                        $this->error("发布失败!");
                    }

                }else{
                    $this->error("发布内容不全");
                }

            }else{
                $this->error('错误方法');
            }
        }else{
            $this->error('请登录系统');
        }



    }

    //test
    public function test(){
        $user_ext_db = D('UserExt');
        $jobs = $_GET['jobs'];
        $duration = $_GET['duration'];
        $keyword = $_GET['keyword'];
        $result = $user_ext_db->getYInfo($jobs,$duration,$keyword);
        dump($result);
    }



} 
